#coding:utf8
import tkinter as tk
from tkinter.filedialog import askopenfilename
from tkinter import messagebox
from analytical.use_classifier import use_classifier
import os

class UseClassifier(tk.Frame):
    
    def __init__(self, master=None):
        tk.Frame.__init__(self, master)
        self.grid()
        self.createWidgets()
        
    def createWidgets(self):
        self.lb = tk.Label(self,text = '请选择待分析的文件',width="58")
        self.lb.grid(row=0,column=0)
        self.btfile = tk.Button(self,text="选择文件",width="20",command=self.commnent)
        self.btfile.grid(row=1,column=0)
        self.btrs = tk.Button(self,text="开始分析",width="20",command=self.rs)
        self.btrs.grid(row=2,column=0)
    def commnent(self):
        data_dir = os.path.dirname(os.path.dirname(os.getcwd()))+'\\data'
        self.openfilename = askopenfilename(initialdir = data_dir,title = "选择文件",filetypes = (("pkl files","*.pkl"),("all files","*.*")))
        if self.openfilename != '':
            self.lb.config(text = "您选择的文件是："+self.openfilename)

        else:
            self.lb.config(text = "您没有选择任何文件") 
    
    def rs(self):
        if self.openfilename.strip() == "":
            messagebox.showinfo("提示", "你没有选择文件！")
        if self.openfilename.strip() != "": 
            use_classifier(self.openfilename)   
            messagebox.showinfo("提示", "分析成功！")       